package com.smartlink.service;

import java.util.Calendar;

import com.smartlink.dao.SettingDaoImpl;
import com.smartlink.pojo.Setting;

public class SettingService {
	private SettingDaoImpl settingDaoImpl;

	public void setSettingDaoImpl(SettingDaoImpl settingDaoImpl) {
		this.settingDaoImpl = settingDaoImpl;
	}

	public Setting getSettingById(String id) {
		return settingDaoImpl.findById(Integer.parseInt(id));
	}

	public void update(Setting setting) {
		java.util.Calendar beginTime = java.util.Calendar.getInstance();
		java.util.Calendar overTime = java.util.Calendar.getInstance();
		beginTime.setTime(setting.getAlarmBeginDate());
		overTime.setTime(setting.getAlarmOverDate());
		int beginHour = beginTime.get(Calendar.HOUR_OF_DAY);
		int overHour = overTime.get(Calendar.HOUR_OF_DAY);
		if (beginHour > overHour) {
			overTime.add(Calendar.DAY_OF_MONTH, 1);
		}
		setting.setAlarmBeginDate(beginTime.getTime());
		setting.setAlarmOverDate(overTime.getTime());

		settingDaoImpl.update(setting);

	}

}
